'use strict';

sitaApp.factory('Category', ['$resource', function ($resource) {
    return $resource('/tinterest/v1/category/:method/', {method: '@method'}, {
        addCategory: {
            method: 'POST',
            params: {method: 'addupdate'},
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        },
        remove: {method: 'POST', params: {method: 'remove'}, headers: {'Content-Type': 'application/json'}},
        listCategory: {
            method: 'POST', params: {method: 'list'}, headers: {
                'Content-Type': 'application/json'
            }
        }

    })
}]);

sitaApp.factory('Program', ['$resource', function ($resource) {
    return $resource('/tinterest/v1/program/:method/', {method: '@method'}, {
        addProgram: {method: 'POST', params: {method: 'addupdate'}, headers: {'Content-Type': 'application/json'}},
        listProgram: {method: 'POST', params: {method: 'list'}, headers: {'Content-Type': 'application/json'}}
    });
}]);

sitaApp.factory('Resource', ['$resource', function ($resource) {

    return $resource('/tinterest/v1/resources/:method', {method: '@method'}, {
        listResource: {method: 'POST', params: {method: 'list'}, headers: {'Content-Type': 'application/json'}}
    });
}]);

sitaApp.directive('fileModel', ['$parse', function ($parse) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            var model = $parse(attrs.fileModel);
            var modelSetter = model.assign;

            element.bind('change', function () {
                scope.$apply(function () {
                    modelSetter(scope, element[0].files[0]);
                });
            });
        }
    };
}]);
//
//sitaApp.dwr('multiPartForm', ['$http', function($http) {
//    this.post = function(uploadUrl, data) {
//        var fd = new FormData();
//        for(var key in data) {
//            fd.append(key, data[key]);
//        }
//        $http.post(uploadUrl, fd, {
//            transformRequest: angular.identity,
//            headers: {'Content-Type': undefined}
//        })
//    }
//}]);